import json,os
import numpy as np
import cv2
import mxnet.ndarray as nd
from data.bbox.bbox_dataset import DetectionDataset
class bdd100kDataset(DetectionDataset):
    def __init__(self, anno_path, img_root, transforms = None):
        super(bdd100kDataset,self).__init__()
        self.objs = json.load(open(anno_path,"rt"))
        self.classes = ["bike","bus","car","motor","person","rider","traffic light","traffic sign","truck"]
        self.img_root = img_root
    def at_with_image_path(self, idx):
        obj = self.objs[idx]
        name = obj["name"]
        labels = obj["labels"]
        bboxes = []
        for l in labels:
            category = l["category"]
            if category in self.classes:
                box2d = l["box2d"]
                x1,y1,x2,y2 = float(box2d["x1"]),float(box2d["y1"]),float(box2d["x2"]),float(box2d["y2"]),
                cls = self.classes.index(category)
                bboxes.append([x1,y1,x2,y2,cls,0])
        return os.path.join(self.img_root,name), np.array(bboxes)
    def __len__(self):
        return len(self.objs)
if __name__ == '__main__':
    da= bdd100kDataset("/data1/zyx/yks/dataset/bdd100k/labels/bdd100k_labels_images_train.json",
                       "/data1/zyx/yks/dataset/bdd100k/images/bdd100k/images/100k/train")
    datrain = da.to_roidb("/data1/zyx/yks/dataset/bdd100k/labels/train.roidb")
    da= bdd100kDataset("/data1/zyx/yks/dataset/bdd100k/labels/bdd100k_labels_images_train.json",
                       "/data1/zyx/yks/dataset/bdd100k/images/bdd100k/images/100k/train")
    datrain = da.to_roidb("/data1/zyx/yks/dataset/bdd100k/labels/train.roidb")
    davalminusminival =
    # print len(da)